package com.xzh.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzh.entity.CarInformation;
import com.xzh.mapper.CarInMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CarInService {

    @Resource
    private CarInMapper carinmapper;

    public List<CarInformation> selectAll(CarInformation e) {
        return carinmapper.selectALL(e);
    }

    //查询用户数据及页码数接口
    public PageInfo<CarInformation> selectPage(CarInformation e, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<CarInformation> list = carinmapper.selectALL(e);
        return PageInfo.of(list);
    }

    //发布拼车接口
    public void add(CarInformation e) {
        carinmapper.insert(e);
    }

    //更新拼车订单status接口
    @Transactional
    public void updateOrderStatus(CarInformation e) {
        carinmapper.updateOrderStatus(e);
    }

    public CarInformation getCarInformation(int userId) {
        return carinmapper.getCarInformation(userId);
    }
}
